package jed.DistributedEventingTests;

import javaEventing.EventManager;
import jed.DistributedEventManagerExtension;
import jed.DistributedEventObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by Espen Skjervold, FFI, 01.feb.2011
 */
public class ChatAppExample {
    public static void main(String[] args) {

       EventManager.setEventManagerExtension(new DistributedEventManagerExtension());

       EventManager.registerEventListener(new EventManager.GenericEventListener() {
            public void eventTriggered(Object sender, EventManager.Event event) {
                System.out.println("Chat message: " + event.getPayload());
            }
        }, new DistributedEventObject());


        while (true) {
           try {
                String message = (new BufferedReader(new InputStreamReader(System.in)).readLine());
                EventManager.triggerEvent(null, new DistributedEventObject(message));
            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
    }
}
